<?php

namespace app\common\model\xilumarket;

use think\Model;

class User extends Model
{

    // 表名
    protected $name = 'user';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [
        'logintime_text'
    ];

    public function getLogintimeTextAttr($value, $data)
    {
        if (!isset($data['logintime'])) {
            $value = '未知';
        } else {
            $diff = time() - $data['logintime'];
            if ($diff <= 86400) {
                $value = $diff <= 3600 ? "刚刚来过" : bcdiv($diff,3600).'小时前来过';
            } else {
                $value = xilumarket_time_cha(time(),$data['logintime']).'来过';
            }
        }
        return $value;
    }
    public function getAvatarAttr($value,$data){
        return isset($value) &&$value ?cdnurl($value,true):'';
    }

}
